import { assign } from 'lodash';
import { AnyAction } from 'redux';
import ACTIONS from 'constants/page';

const initialState: Record<string, any> = {
  pageTotal: 0,
  pageList: [],
};

export default (state = initialState, action: AnyAction) => {
  switch (action.type) {
    case ACTIONS.FETCH_LIST_SUCCESS:
      return assign({}, state, {
        pageTotal: action.response.data.total,
        pageList: action.response.data.items,
      });

    default:
      return state;
  }
};
